What is p-finally?
The p-finally npm package is designed to allow you to attach a handler that will be called when a promise is settled (either fulfilled or rejected). This is useful for running cleanup code or finalizing operations, regardless of the promise's outcome.
Attaching a finally handler to a promise
This feature allows you to execute code after a promise has been settled, regardless of whether it was fulfilled or rejected. It's particularly useful for cleanup operations.
const pFinally = require('p-finally');
const promise = new Promise((resolve, reject) => {
// Some asynchronous operation
});
pFinally(promise, () => {
// Code to run on promise settlement
});